package com.example.yls.demoa;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;

public class MainActivity extends AppCompatActivity {
            private MyView wuziqiPanel;
            private String matchID="123456";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        wuziqiPanel=findViewById(R.id.id_wuziqi);
        //启动一个定时器，每隔500毫秒查询一下该盘对战
        starTimerForQuery();

    }

    private void starTimerForQuery() {
        Timer timer=new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                BmobQuery<wuzidata>wuzidataBmobQuery=new BmobQuery<>();
                wuzidataBmobQuery.addWhereEqualTo("matchId",matchID);
                wuzidataBmobQuery.findObjects(new FindListener<wuzidata>() {
                    @Override
                    public void done(List<wuzidata> list, BmobException e) {
                        if (e==null&&list!=null&&list.size()>0){
                            wuzidata wuzidatas=list.get(0);
                            wuziqiPanel.setData(wuzidatas);
                        }
                    }
                });

            }
        },500,500);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main,menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id=item.getItemId();
        if (id==R.id.action_setting){
            wuziqiPanel.ReStar();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
